<template>
  <div class="list-container">
    <div
      v-for="(item, index) in dataList"
      :key="index"
      class="list-item"
      @click="showDetail(item)"
    >
      <div class="type" :class="item.status !== null ? 'answered' : ''">
        <span>{{ item.quType | questionTypeFilter }}</span>
        <span>{{ item.status !== null ? '已做答' : '' }}</span>
      </div>
      <div class="brief">题目：{{ item.quContent }}</div>
      <div class="tips">
        <span>{{ item.quBankName }}</span>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'DataList',
  filters: {
    questionTypeFilter(id) {
      const questionType = {
        1: 'A1型题',
        2: 'X型题',
        3: 'A3/4型题',
        4: 'B型题',
        5: 'A2型题'
      }
      return questionType[id]
    }
  },
  props: {
    list: {
      type: Array,
      default() {
        return []
      },
      required: true
    }
  },
  data() {
    return {
      dataList: this.list
    }
  },
  methods: {
    // 跳转到课程详情
    showDetail(detailInfo) {
      // console.log(detailInfo)
      this.$emit('detail', detailInfo)
    }
  }
}
</script>

<style lang="scss" scoped>
// 列表容器
.list-container {
  height: 100%;
  width: 100%;
  display: flex;
  flex-wrap: wrap;
  background-color: rgba(160, 212, 244, 0.126);
  // 每一项
  .list-item {
    // 底部有适配该item的hover
    position: relative;
    width: 260px;
    height: 200px;
    margin: 0px 6px 12px;

    // padding: 10px;
    border: 1px solid #f0f0f0;
    border-radius: 8px;
    box-sizing: border-box;
    cursor: pointer;
    overflow: hidden;
    transition: 0.15s;

    // 标题、时长、简介
    .type {
      display: flex;
      justify-content: space-between;
      font-size: 12px;
      color: #ffffff;
      background-color: #44b1f4;
      padding: 10px 10px 5px;
    }
    .noanswered {
      background-color: rgb(245, 124, 124);
    }
    .answered {
      background-color: #44b1f4;
    }

    .brief {
      font-size: 14px;
      color: #6d737b;
      padding: 10px 10px 0px;
    }

    .tips {
      display: block;
      width: 100%;
      position: absolute;
      bottom: 0px;
      font-size: 12px;
      color: #909399;
      text-align: right;
      padding: 5px 10px;
      box-sizing: border-box;
      background-color: #ffffff;
      border-top: 1px solid #ebeef5;
    }

    // .title {
    //   width: calc(220px-10px);
    //   font-weight: 600;
    //   padding: 5px 0px 10px;
    //   border-bottom: 1px solid #ebeef5;
    //   white-space: nowrap;
    //   overflow: hidden;
    //   text-overflow: ellipsis;
    // }
    .brief {
      width: calc(220px - 10px);
      line-height: 19px;
      display: -webkit-box;
      -webkit-box-orient: vertical;
      -webkit-line-clamp: 7;
      -o-text-overflow: ellipsis;
      overflow: hidden;
      text-overflow: ellipsis;
    }
  }
}

// 只适配支持hover的设备
@media (any-hover: hover) {
  .list-container .list-item:hover {
    box-shadow: rgba(0, 0, 0, 0.2) 0px 5px 10px;
  }
}
</style>
